package com.atstudy.state;

/**
 * @version v1.0
 * @description:
 * @author: admin
 * @date: 2022/12/23 14:57
 * @copyright: 博为峰
 */
public class WaitDemo {
    public static Object obj = new Object();

    public static void main(String[] args) {
        new Thread(new Runnable() {//Thread-0
            @Override
            public void run() {
                synchronized (obj) {
                    System.out.println(Thread.currentThread().getName() + "-A");
                    try {
                        obj.wait();//释放锁
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    System.out.println(Thread.currentThread().getName() + "-B");
                }
            }
        }).start();

        try {
            Thread.sleep(1000);//不释放锁
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        synchronized (obj) {
            System.out.println(Thread.currentThread().getName() + "-C");
            obj.notify();
        }
    }
}
